import { Controller, Get, Param, ParseIntPipe, UseGuards } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { RedisService } from 'src/redis/redis.service'
import { UserService } from './user.service'

@Controller('user')
export class UserController {
  constructor(
    private readonly userService: UserService,
    private redisService: RedisService
  ) {}

  @UseGuards(AuthGuard('jwt'))
  @Get('userList')
  public userList() {
    return this.userService.findAllUser()
  }

  @UseGuards(AuthGuard('jwt'))
  @Get('getUser/:id')
  public getUser(@Param('id', new ParseIntPipe()) id: number) {
    return this.redisService.cache(`/user/getUser/${id}`, () =>
      this.userService.findById(id)
    )
  }
}
